/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.bis.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.common.utils.excel.annotation.ExcelFields;
import com.jeesite.common.utils.excel.fieldtype.CompanyType;
import com.jeesite.common.utils.excel.fieldtype.OfficeType;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 派单管理Entity
 * @author Zhangning
 * @version 2019-08-24
 */
@Table(name="bis_dispatch", alias="a", columns={
		@Column(name="id", attrName="id", label="id", isPK=true),
		@Column(name="order_no", attrName="orderNo", label="订单号"),
		@Column(name="dipatch_type", attrName="dipatchType", label="派单类型", comment="派单类型：1.派单 2.抢单"),
		@Column(name="order_status", attrName="orderStatus", label="状态", comment="1.等待接单 2.已接单 3.已完成 4.已拒绝"),
		@Column(name="province", attrName="province", label="省"),
		@Column(name="city", attrName="city", label="城市"),
		@Column(name="province_id", attrName="provinceId", label="省ID"),
		@Column(name="area", attrName="area", label="区域"),
		@Column(name="address", attrName="address", label="地址"),
		@Column(name="city_id", attrName="cityId", label="城市ID"),
		@Column(name="sender_name", attrName="senderName", label="寄件人名称", queryType=QueryType.LIKE),
		@Column(name="sender_phone", attrName="senderPhone", label="寄件人电话"),
		@Column(name="area_id", attrName="areaId", label="区域ID"),
		@Column(name="sender_time", attrName="senderTime", label="取件时间"),
		@Column(name="order_time", attrName="orderTime", label="下单时间"),
		@Column(includeEntity=DataEntity.class),
		@Column(name="assignor_id", attrName="assignorId", label="指派人Id"),
		@Column(name="assignor_name", attrName="assignorName", label="指派人名称", queryType=QueryType.LIKE),
		@Column(name="red_packets", attrName="redPackets", label="红包"),
	}, orderBy="a.update_date DESC"
)
public class BisDispatch extends DataEntity<BisDispatch> {
	@Valid
	@ExcelFields({@ExcelField(
			title = "订单号",
			attrName = "id",
			align = ExcelField.Align.CENTER,
			sort = 10
	), @ExcelField(
			title = "派单类型(1.派单 2.抢单)",
			attrName = "dipatchType",
			align = ExcelField.Align.CENTER,
			sort = 20
	), @ExcelField(
			title = "订单状态(1.等待接单 2.已接单 3.已完成 4.已拒绝)",
			attrName = "orderStatus",
			align = ExcelField.Align.CENTER,
			sort = 30
	), @ExcelField(
			title = "省",
			attrName = "province",
			align = ExcelField.Align.CENTER,
			sort = 40
	), @ExcelField(
			title = "城市",
			attrName = "city",
			align = ExcelField.Align.LEFT,
			sort = 50
	), @ExcelField(
			title = "区域",
			attrName = "area",
			align = ExcelField.Align.CENTER,
			sort = 60
	), @ExcelField(
			title = "地址",
			attrName = "address",
			align = ExcelField.Align.CENTER,
			sort = 70
	), @ExcelField(
			title = "寄件人名称",
			attrName = "senderName",
			align = ExcelField.Align.CENTER,
			sort = 80
	), @ExcelField(
			title = "寄件人电话",
			attrName = "senderPhone",
			align = ExcelField.Align.CENTER,
			sort = 90
	), @ExcelField(
			title = "取件时间",
			attrName = "senderTime",
			align = ExcelField.Align.CENTER,
			sort = 100,
			dataFormat = "yyyy-MM-dd HH:mm"
	), @ExcelField(
			title = "下单时间",
			attrName = "orderTime",
			align = ExcelField.Align.CENTER,
			sort = 110,
			dataFormat = "yyyy-MM-dd HH:mm"
	), @ExcelField(
			title = "快递员姓名和电话",
			attrName = "assignorName",
			align = ExcelField.Align.CENTER,
			sort = 120
	), @ExcelField(
			title = "红包",
			attrName = "redPackets",
			align = ExcelField.Align.CENTER,
			sort = 130
	)})
	private static final long serialVersionUID = 1L;
	private String orderNo;		// 订单号
	private Long dipatchType;		// 派单类型：1.派单 2.抢单
	private String orderStatus;		// 1.等待接单 2.已接单 3.已完成 4.已拒绝
	private String province;		// 省
	private String city;		// 城市
	private String provinceId;		// 省ID
	private String area;		// 区域
	private String address;		// 地址
	private String cityId;		// 城市ID
	private String senderName;		// 寄件人名称
	private String senderPhone;		// 寄件人电话
	private String areaId;		// 区域ID
	private Date senderTime;		// 取件时间
	private Date orderTime;		// 取件时间
	private String assignorId;		// 指派人Id
	private String assignorName;		// 指派人名称
	private BigDecimal redPackets;		// 红包

	//扩展字段
	private Integer delayMinute = Integer.parseInt(Global.getConfig("bis.dispatch.overtime.minutes","10")); //订单超时分钟

	public BisDispatch() {
		this(null);
	}

	public BisDispatch(String id){
		super(id);
	}
	
	@Length(min=0, max=20, message="订单号长度不能超过 20 个字符")
	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}
	
	public Long getDipatchType() {
		return dipatchType;
	}

	public void setDipatchType(Long dipatchType) {
		this.dipatchType = dipatchType;
	}
	
	@Length(min=0, max=40, message="省长度不能超过 40 个字符")
	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}
	
	@Length(min=0, max=40, message="城市长度不能超过 40 个字符")
	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}
	
	@Length(min=0, max=64, message="省ID长度不能超过 64 个字符")
	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}
	
	@Length(min=0, max=40, message="区域长度不能超过 40 个字符")
	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}
	
	@Length(min=0, max=255, message="地址长度不能超过 255 个字符")
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	@Length(min=0, max=64, message="城市ID长度不能超过 64 个字符")
	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}
	
	@Length(min=0, max=20, message="寄件人名称长度不能超过 20 个字符")
	public String getSenderName() {
		return senderName;
	}

	public void setSenderName(String senderName) {
		this.senderName = senderName;
	}
	
	@Length(min=0, max=20, message="寄件人电话长度不能超过 20 个字符")
	public String getSenderPhone() {
		return senderPhone;
	}

	public void setSenderPhone(String senderPhone) {
		this.senderPhone = senderPhone;
	}
	
	@Length(min=0, max=64, message="区域ID长度不能超过 64 个字符")
	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getSenderTime() {
		return senderTime;
	}

	public void setSenderTime(Date senderTime) {
		this.senderTime = senderTime;
	}
	
	@Length(min=0, max=64, message="指派人Id长度不能超过 64 个字符")
	public String getAssignorId() {
		return assignorId;
	}

	public void setAssignorId(String assignorId) {
		this.assignorId = assignorId;
	}
	
	@Length(min=0, max=20, message="指派人名称长度不能超过 20 个字符")
	public String getAssignorName() {
		return assignorName;
	}

	public void setAssignorName(String assignorName) {
		this.assignorName = assignorName;
	}

	public String getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}

	public Integer getDelayMinute() {
		return delayMinute;
	}

	public void setDelayMinute(Integer delayMinute) {
		this.delayMinute = delayMinute;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(Date orderTime) {
		this.orderTime = orderTime;
	}

	public BigDecimal getRedPackets() {
		return redPackets;
	}

	public void setRedPackets(BigDecimal redPackets) {
		this.redPackets = redPackets;
	}

	public Date getSenderTime_gte(){
		return sqlMap.getWhere().getValue("sender_time", QueryType.GTE);
	}

	public void setSenderTime_gte(Date senderTime){
		senderTime = DateUtils.getOfDayFirst(senderTime); // 将日期的时间改为0点0分0秒
		sqlMap.getWhere().and("sender_time", QueryType.GTE, senderTime);
	}

	public Date getSenderTime_lte(){
		return sqlMap.getWhere().getValue("sender_time", QueryType.LTE);
	}

	public void setSenderTime_lte(Date senderTime){
		senderTime = DateUtils.getOfDayLast(senderTime); // 将日期的时间改为23点59分59秒
		sqlMap.getWhere().and("sender_time", QueryType.LTE, senderTime);
	}
}